﻿using System.Collections.Generic;
using System.Linq;
using Headsight.BPMN2WF.BPMN.Schemas;

namespace Headsight.BPMN2WF.BPMN.Model
{
    /// <summary>
    /// <see cref="BPMNFlowNodeFactory"/> default implementation.
    /// </summary>
    public class BPMNFlowNodeFactoryImpl : BPMNFlowNodeFactory
    {
        public override IList<BPMNFlowNode> CreateBPMNFlowNodes(tProcess tProcess, IList<BPMNSequenceFlow> bpmnSequenceFlows, BPMNProcessFactoryParams bpmnModelFactoryParams)
        {
            var result = new List<BPMNFlowNode>();
            var tFlowNodes = tProcess.Items.Where(x => typeof(tFlowNode).IsAssignableFrom(x.GetType())).ToArray();

            foreach (var each in tFlowNodes)
            {
                var argsIn = bpmnModelFactoryParams.BpmnModelFactory.CreateArgumentsIn(each);
                var argsOut = bpmnModelFactoryParams.BpmnModelFactory.CreateArgumentsOut(each);

                result.Add(new BPMNFlowNode((tFlowNode)each, argsIn, argsOut));
            }

            return result;
        }
    }
}